package terra.network.packet.client;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;


public class RequestCraftItem extends Packet {

	public final static int COUNT = 9;
	public int playerId;
	public int itemOids[] = new int[COUNT];
	public int itemIds[] = new int[COUNT];
	public int itemCounts[] = new int[COUNT];
	
	public RequestCraftItem(int playerId) {
		this.playerId = playerId;
	}

	public RequestCraftItem() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = getNewBuffer();
		buf.writeByte(getId());
		buf.writeInt(playerId);
		for(int i = 0; i < COUNT;i++){
			buf.writeInt(itemOids[i]);
			buf.writeInt(itemIds[i]);
			buf.writeInt(itemCounts[i]);
		}
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		playerId = buf.readInt();
		for(int i = 0; i < COUNT;i++){
			itemOids[i] = buf.readInt();
			itemIds[i] = buf.readInt();
			itemCounts[i] = buf.readInt();
		}
		return this;
	}

	@Override
	public int getLength() {
		return 5+108;
	}

	@Override
	public boolean isDynamicLength() {
		return false;
	}

	@Override
	public byte getId() {
		return 24;
	}

	@Override
	public byte getPriority() {
		return PRIOR_NORMAL;
	}

}
